<template>
	<view class="wrapForm">
		<view class="bgLine"></view>
		<view class="wrapFormBody pL15 pR15 pT15">
			<view class="flex jst-between u-border-bottom pT15 pB15" v-if="isBind">
				<view>已绑定微信授权</view>
				<view  @click="unbindWechat" style="color: #386aff">解绑微信<u-icon name="arrow-right" :color="'#8d8d8d'"></u-icon></view>
			</view>
			<view v-else class="flex jst-between u-border-bottom pT15 pB15" >
				<view>未绑定微信授权</view>
				<view @click="bindWechat" style="color: #386aff">绑定微信<u-icon name="arrow-right" :color="'#8d8d8d'"></u-icon></view>
			</view>
			<view class="flex jst-between u-border-bottom pT15 pB15"
				@click="xf.onlineUtils.route('pages/userPage/subpackge/my/yhxy/yhxy?type=YHXY')">
				<view>用户协议</view>
				<u-icon name="arrow-right" :color="'#8d8d8d'"></u-icon>
			</view>
			<view class="flex jst-between pT15 pB15 u-border-bottom"
				@click="xf.onlineUtils.route('pages/userPage/subpackge/my/yhxy/yhxy?type=YSZC')">
				<view>隐私政策</view>
				<u-icon name="arrow-right" :color="'#8d8d8d'"></u-icon>
			</view>
			<view class="flex jst-between pT15 pB15"
				@click="xf.onlineUtils.route('pages/common/destroyAccount/index?type=ZXZH')">
				<view>注销账号</view>
				<u-icon name="arrow-right" :color="'#8d8d8d'"></u-icon>
			</view>
		</view>
		<view class="flex jst-center bottomW">
			<view class="pointer rightNowPay u-f font15 t-center" @click="logOut">
				退出登录
			</view>
		</view>
		<xfTipModal ref="tipModal"></xfTipModal>
	</view>
</template>

<script>
	import { bindWxDetails, usergetOpenId, unbindWx, bindWx } from '@/api/common.js'
	export default {
		data() {
			return {
				isBind: false,
				openId: ''
			}
		},
		onLoad() {
			this.getWechatLogin()
		},
		methods: {
			getWechatLogin() { //// 获取微信unionid openId方法
				uni.login({
					provider: 'weixin', // 指定授权方式为微信
					success: (res) => {
						usergetOpenId({
							type: '3', // 获取类型 网站登录订阅 1 推送订阅2 小程序3
							code: res.code
						}).then(async res => {
							this.openId = res.result
							this.bindWechatApi(res.result)
						});
						},
						fail: (err) => {

						}
				});
			},
			bindWechatApi(openId){
				bindWxDetails({openId}).then(res=>{
					// 是否绑定
					this.isBind = res.result
				})
			},
			unbindWechat(){
				let that = this
				that.$refs.tipModal.open({
					content: "请确认是否解绑微信",
					btnText: "确定",
					showCancel: true,
					success: function() {
						unbindWx({
							openId: that.openId
						}).then(res=>{
							that.bindWechatApi(that.openId)
							that.xf.onlineUtils.toast('解绑成功!')
						})
					}
				})
			},
			bindWechat() {
				let that = this
				that.$refs.tipModal.open({
					content: "请确认是否绑定微信",
					btnText: "确定",
					showCancel: true,
					success: function() {
						bindWx({
							openId: that.openId
						}).then(res=>{
							that.bindWechatApi(that.openId)
							that.xf.onlineUtils.toast('绑定成功!')
						})
					}
				})
			},
			logOut() {
				uni.clearStorageSync()
				getApp().$vm.exit()
				this.xf.onlineUtils.toast('退出登录成功!')
				// #ifdef MP-COMPANY || MP-ECONOMIC
				setTimeout(() => {
					uni.reLaunch({
						url: "/pages/login/login"
					})
				}, 1000)
				// #endif
				// #ifdef MP-USER
				setTimeout(() => {
					uni.switchTab({
						url: "/pages/userPage/home/index"
					})
				}, 1000)
				// #endif
			}
		}
	}
</script>
<style lang="scss">
	page {

		/* #ifdef MP-WEIXIN */
		height: 100%;
		/* #endif */
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>
	.wrapForm {

		height: 100%;

		.wrapFormBody {
			margin-top: -30rpx;
			border-radius: 40rpx 40rpx 0 0;
			background: #fff;
		}

		.uni-forms-item {
			align-items: center !important;
		}
	}

	.bgLine {
		/* #ifdef MP-USER */
		background-color: #E1EEFF;
		/* #endif */
		/* #ifdef MP-COMPANY */
		background-color: #EBF0FF;
		/* #endif */
		/* #ifdef MP-ECONOMIC */
		background-color: #EBFCFF;
		/* #endif */
		width: 100%;
		height: 60rpx;
	}

	.bottomW {
		position: fixed;
		bottom: 40rpx;
		width: 100%;
		left: 0;
	}

	.rightNowPay {
		width: 670rpx;
		height: 100rpx;
		line-height: 100rpx;
		background: #EB392F;
		border-radius: 30rpx;

	}
</style>